www.gusucode.com > VC++ 酒店管理系统-源码程序 > VC++ 酒店管理系统-源码程序/code/hotel2003/BillInfoLookup.cpp

    // BillInfoLookup.cpp : implementation file
// Download by http://www.NewXing.com

#include "stdafx.h"
#include "qq.h"
#include "BillInfoLookup.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CBillInfoLookup dialog
CString CBillInfoLookup::STRINGS[100]={""};

CBillInfoLookup::CBillInfoLookup(CWnd* pParent /*=NULL*/)
	: CDialog(CBillInfoLookup::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBillInfoLookup)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	BillCode = _T("");
	HandCode = _T("");
	Sum = 0;
	Paid = 0;
	Rebate = _T("");
	Striked = FALSE;
	bSuccess=false;
}


void CBillInfoLookup::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBillInfoLookup)
	DDX_Control(pDX, IDC_COMBO1, m_InfoLookup_BillCode);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBillInfoLookup, CDialog)
	//{{AFX_MSG_MAP(CBillInfoLookup)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBillInfoLookup message handlers

BOOL CBillInfoLookup::OnInitDialog() 
{
	CDialog::OnInitDialog();
	HICON m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME2);
	this->SetIcon(m_hIcon,true);
	// TODO: Add extra initialization here
	m_acCombo.Init(GetDlgItem(IDC_COMBO1));
	if(!m_BillInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE))
	{
		MessageBox("查询数据库失败或者数据库没有连接!",
			       "数据库错误",
				   MB_OK
			      );
		return false;
	}
	InitDate();//
	m_BillInfoSet.MoveFirst();//move to the first record
	int i=0;
    while(!m_BillInfoSet.IsEOF())
	{
        STRINGS[i]=m_BillInfoSet.m_BillCode;
         m_BillInfoSet.MoveNext();
		 i++;
	}
    m_BillInfoSet.Close();//关闭数据库
    for (int j=0;(!STRINGS[j].IsEmpty()); j++)
	{
		m_acCombo.GetStringList().Add(STRINGS[j].GetBuffer(STRINGS[j].GetLength()));
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CBillInfoLookup::OnOK() 
{
	// TODO: Add extra validation here
	CString str;
	m_InfoLookup_BillCode.GetWindowText(str);
    if(str=="")
	{
		MessageBox("请输入帐单号码!","手牌号错误",MB_OK);
		return ;
	}
	if(!m_BillInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE))
	{
		MessageBox("查询数据库失败或者数据库没有连接!",
			"数据库错误",
			MB_OK
			      );
		bSuccess=false;
		return ;
	}
	bool bInSQL=false;//是否存在这个数据记录
	m_BillInfoSet.MoveFirst();
	while(!m_BillInfoSet.IsEOF())
	{
         if(m_BillInfoSet.m_BillCode==str)
		 {
			 bInSQL=true;
			 break;
		 }
		 else bInSQL=false;
         m_BillInfoSet.MoveNext();
	}
	///////////////////////////////////////////////////////////
//	查询成功的话保存得到的数据
 if(bInSQL)
 {
	BillCode=m_BillInfoSet.m_BillCode;
    HandCode=m_BillInfoSet.m_HandCode;
	Sum=m_BillInfoSet.m_Sum;
	Paid=m_BillInfoSet.m_Paid;
	Rebate=m_BillInfoSet.m_Rebate;
    Striked=m_BillInfoSet.m_Striked;
	bSuccess=true;

 }
 else
 {
	 MessageBox("该记录不存在!","数据库错误",MB_OK);
	 bSuccess=false;
	 m_BillInfoSet.Close();//关闭数据库返回
	 return ;
 }
   	////保存数据完成关闭数据库
    m_BillInfoSet.Close();
	CDialog::OnOK();
}

void CBillInfoLookup::InitDate()
{
   for(int i=0;i<100;i++)
   {
	   STRINGS[i]="";
   }
}